<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>可拖拽的路线规划</title>
    <style>
        html,
        body,
        #container {
            width: 100%;
            height: 100%;
        }
    </style>
    <script  th:src="@{/js/jquery.min.js}" type="text/javascript"></script>
    <script th:src="@{/ajax/libs/layer/layer.min.js}"></script>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
    <script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=948066487cbe8e187b2560b8d9e5940b&plugin=AMap.Driving"></script>
    <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
</head>
<body>
<div id="container"></div>
<div id="panel"></div>
<script type="text/javascript">
    //基本地图加载
    var map = new AMap.Map("container", {
        resizeEnable: true,
        center: [116.397428, 39.90923],//地图中心点
        zoom: 13 //地图显示的缩放级别
    });
    //构造路线导航类
    var driving = new AMap.Driving({
        map: map,
        panel: "panel"
    });
    // 根据起终点经纬度规划驾车导航路线

        $(function () {
            $.ajax({url:"/inspection/dian/allDian",type:"post",async:true,success:function (reslut) {
                    if (reslut.code ==200) {
                        reslut.list.forEach(function(dian) {
                            var ds=new AMap.Marker({
                                map: map,
                                icon:'//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
                                position: [dian.along, dian.latitude],
                                offset: new AMap.Pixel(-13, -30)
                            });
                        });
                        map.setFitView();
                    }else{
                        layer.msg(reslut.mag, {icon: 2});
                    }
                },error:function () {
                    layer.msg("操作失败", {icon: 2});
                }
            });
        })

    driving.search(new AMap.LngLat(116.379028, 39.865042), new AMap.LngLat(116.427281, 39.903719),{
        waypoints:[new AMap.LngLat(116.379028, 39.885042),new AMap.LngLat(116.379028, 39.875042)]
    }, function(status, result) {
        // result 即是对应的驾车导航信息，相关数据结构文档请参考  https://lbs.amap.com/api/javascript-api/reference/route-search#m_DrivingResult
        if (status === 'complete') {
            log.success('绘制驾车路线完成')
            map.setFitView();
        } else {
            log.error('获取驾车数据失败：' + result)
        }
    });
</script>
</body>
</html>